Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider the C function given below.int f(int... Start Learning for Free
Consider the C function given below.
int f(int j)
{
  static int i = 50;
  int k;
  if (i == j)
  {
    printf(“something”);
    k = f(i);
    return 0;
  }
  else return 0;
}
Which one of the following is TRUE?
  • a)
    The function returns 0 for all values of j.
  • b)
    The function prints the string something for all values of j.
  • c)
    The function returns 0 when j = 50.
  • d)
    The function will exhaust the runtime stack or run into an infinite loop when j = 50
Correct answer is option 'D'. Can you explain this answer?
Most Upvoted Answer
Consider the C function given below.int f(int j){ static int i = 50; i...
Understanding the Function Behavior
The function `f(int j)` contains a static variable `i` initialized to 50. It checks if `i` equals `j` and behaves differently based on this condition.
Function Execution Flow
- When `f` is called with `j = 50`:
- `i` is 50, so the condition `if (i == j)` is true.
- It prints "something".
- It then calls itself recursively with `k = f(i)`, which is `k = f(50)`.
Infinite Recursion Issue
- Each call to `f(50)` will meet the same condition:
- It will keep printing "something" and call `f(50)` again.
- This creates an infinite loop of function calls, as there is no exit condition for `j = 50`.
Impact on Runtime Stack
- Each recursive call consumes stack space.
- Eventually, the program will run out of stack memory, leading to a stack overflow or crash.
Other Options Explained
- Option A: The function does return 0 for all values of `j`, but this is not the main concern; the infinite loop is the critical issue.
- Option B: It only prints "something" when `j = 50`, not for all values.
- Option C: While it returns 0 when `j = 50`, this does not address the infinite recursion problem.
In conclusion, the correct answer is option D: the function will exhaust the runtime stack or run into an infinite loop when `j = 50`.
Community Answer
Consider the C function given below.int f(int j){ static int i = 50; i...
When j is 50, the function would call itself again and again as neither i nor j is changed inside the recursion.
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Top Courses for Computer Science Engineering (CSE)

Consider the C function given below.int f(int j){ static int i = 50; int k; if (i == j) { printf(“something”); k = f(i); return 0; } else return 0;}Which one of the following is TRUE?a)The function returns 0 for all values of j.b)The function prints the string something for all values of j.c)The function returns 0 when j = 50.d)The function will exhaust the runtime stack or run into an infinite loop when j = 50Correct answer is option 'D'. Can you explain this answer?
Question Description
Consider the C function given below.int f(int j){ static int i = 50; int k; if (i == j) { printf(“something”); k = f(i); return 0; } else return 0;}Which one of the following is TRUE?a)The function returns 0 for all values of j.b)The function prints the string something for all values of j.c)The function returns 0 when j = 50.d)The function will exhaust the runtime stack or run into an infinite loop when j = 50Correct answer is option 'D'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider the C function given below.int f(int j){ static int i = 50; int k; if (i == j) { printf(“something”); k = f(i); return 0; } else return 0;}Which one of the following is TRUE?a)The function returns 0 for all values of j.b)The function prints the string something for all values of j.c)The function returns 0 when j = 50.d)The function will exhaust the runtime stack or run into an infinite loop when j = 50Correct answer is option 'D'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the C function given below.int f(int j){ static int i = 50; int k; if (i == j) { printf(“something”); k = f(i); return 0; } else return 0;}Which one of the following is TRUE?a)The function returns 0 for all values of j.b)The function prints the string something for all values of j.c)The function returns 0 when j = 50.d)The function will exhaust the runtime stack or run into an infinite loop when j = 50Correct answer is option 'D'. Can you explain this answer?.
Solutions for Consider the C function given below.int f(int j){ static int i = 50; int k; if (i == j) { printf(“something”); k = f(i); return 0; } else return 0;}Which one of the following is TRUE?a)The function returns 0 for all values of j.b)The function prints the string something for all values of j.c)The function returns 0 when j = 50.d)The function will exhaust the runtime stack or run into an infinite loop when j = 50Correct answer is option 'D'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider the C function given below.int f(int j){ static int i = 50; int k; if (i == j) { printf(“something”); k = f(i); return 0; } else return 0;}Which one of the following is TRUE?a)The function returns 0 for all values of j.b)The function prints the string something for all values of j.c)The function returns 0 when j = 50.d)The function will exhaust the runtime stack or run into an infinite loop when j = 50Correct answer is option 'D'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the C function given below.int f(int j){ static int i = 50; int k; if (i == j) { printf(“something”); k = f(i); return 0; } else return 0;}Which one of the following is TRUE?a)The function returns 0 for all values of j.b)The function prints the string something for all values of j.c)The function returns 0 when j = 50.d)The function will exhaust the runtime stack or run into an infinite loop when j = 50Correct answer is option 'D'. Can you explain this answer?, a detailed solution for Consider the C function given below.int f(int j){ static int i = 50; int k; if (i == j) { printf(“something”); k = f(i); return 0; } else return 0;}Which one of the following is TRUE?a)The function returns 0 for all values of j.b)The function prints the string something for all values of j.c)The function returns 0 when j = 50.d)The function will exhaust the runtime stack or run into an infinite loop when j = 50Correct answer is option 'D'. Can you explain this answer? has been provided alongside types of Consider the C function given below.int f(int j){ static int i = 50; int k; if (i == j) { printf(“something”); k = f(i); return 0; } else return 0;}Which one of the following is TRUE?a)The function returns 0 for all values of j.b)The function prints the string something for all values of j.c)The function returns 0 when j = 50.d)The function will exhaust the runtime stack or run into an infinite loop when j = 50Correct answer is option 'D'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the C function given below.int f(int j){ static int i = 50; int k; if (i == j) { printf(“something”); k = f(i); return 0; } else return 0;}Which one of the following is TRUE?a)The function returns 0 for all values of j.b)The function prints the string something for all values of j.c)The function returns 0 when j = 50.d)The function will exhaust the runtime stack or run into an infinite loop when j = 50Correct answer is option 'D'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev